<?php

namespace app\admin\model;

use think\Model;

/**
 * 企业招聘
 * Class Recruit
 * @package app\admin\model
 */
class Recruit extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $name = 'enterprise_recruit';

    /**
     * 企业招聘列表
     * @param $where
     * @param $page
     * @param $pagesize
     * @return array
     */
    public static function getRecruitList($where, $page, $pagesize)
    {
        $data = self::alias('er')
            ->join('enterprise e', 'e.id = er.eid', 'left')
            ->join('location c', 'c.location_id = e.city', 'left')
            ->join('users u', 'u.id = er.uid', 'left')
            ->field('er.*,e.cid,e.qrcode,e.name as ename,c.name as city_name,u.headimg,u.nickname')
            ->where($where)
            ->page($page, $pagesize)
            ->order('er.create_time', 'desc')
            ->select();

        return $data ? $data->toArray() : [];
    }

    /**
     * 企业招聘统计
     * @param $where
     * @return int
     */
    public static function countRecruitList($where)
    {
        return self::alias('er')
            ->join('enterprise e', 'e.id = er.eid', 'left')
            ->join('location c', 'c.location_id = e.city', 'left')
            ->join('users u', 'u.id = er.uid', 'left')
            ->where($where)
            ->count();
    }

    /**
     * 指定企业招聘
     * @param $where
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function findRecruit($where)
    {
        $info = self::where($where)->find();

        return $info ? $info->toArray() : [];
    }

    /**
     * 更新企业招聘
     * @param $data
     * @param $where
     * @return Recruit
     */
    public static function updateRecruit($data, $where)
    {
        return self::update($data, $where);
    }

    /**
     * 创建企业招聘
     * @param $data
     * @return Recruit|Model
     */
    public static function createRecruit($data)
    {
        return self::create($data);
    }
}